home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************
- * *
- * Device.C -->> This Program Will Display Device Driver Chains *
- * for Dos 2.xx and 3.00 *
- * *
- * Non-DeSmet Compilers will have to change the following: *
- * _os() --> bdos call -- use bdos() *
- * _peek() --> peek memory -- must assemble seperatly using macro *
- * form. *
- * 05-20-85 *
- * Converted to DeSmet "C" by Lord Rassilon *
- * *
- * 05-01-85 *
- * Dr. Dobb's #103 May 85 pages 119-126 *
- ****************************************************************************/
-
- #define byte char
-
- /* DOS Function Calls */
- #define OPEN_FCB 0x0F
- #define CLOSED_FCB 0x10
- #define VERSION 0x30
-
-
- /* Define Data Structures */
- struct DEVHDR {
- unsigned nxthdr_off; /* Double word ptr to next */
- unsigned nxthdr_seg; /* device header in chain */
- unsigned attr; /* Type of device driver */
- unsigned strat; /* Device strategy entry point */
- unsigned intrpt; /* Interrupt entry point */
- char dname[8]; /* Device name */
- };
-
- struct FCB {
- byte drive; /* Drive designator */
- char fname[11]; /* File or device name */
- unsigned curblk; /* Current block Set to 0 by OPEN_FCB */
- unsigned recsize; /* Logical record size */
- /* (Set to 0x80 by OPEN_FCB) */
- long fsize; /* File size in bytes */
- unsigned date; /* Creation or last update date */
- byte sys_rsv[10]; /* Fields reserved for DOS */
- byte bset[5]; /* Relative record numbers */
- };
-
- struct RSV2_X {
- unsigned time; /* Creation or last update time */
- byte attribute; /* Device or file attribute */
- unsigned dhdr2_off; /* Offset address of device header */
- unsigned dhdr2_seg; /* Segment address of device header */
- byte unknown2[3]; /* Unknown usage */
- };
-
- struct RSV3_X {
- unsigned time; /* Creation or last update time */
- byte attribute; /* Device or file attribute */
- unsigned dhdr3_off; /* Offset address of device header */
- unsigned dhdr3_seg; /* Segment address of device header */
- byte unknown3[2]; /* Unknown usage */
- };
-
- struct DEVHDR device; /* Device header */
- struct FCB device_fcb; /* Standard FCB for device */
- struct RSV2_X *dos2x; /* Reserved field definitions DOS 2.x */
- struct RSV3_X *dos3x; /* Reserved field definitions DOS 3.x */
-
- main()
- {
- int dev_off,dev_seg,i,j;
-
- initfcb(0,"NUL "); /* Set up standard FCB for NUL device */
-
- if (_os(OPEN_FCB,&device_fcb) & 0xFF) { /* Open the device */
- printf("Unable to open device \n");
- exit(1);
- }
-
- /* the reserved fields are allocated differently for DOS 3.x */
- if ((_os(VERSION,0) & 0xFF) ==3) {
- dos3x=(struct RSV3_X *) &device_fcb.sys_rsv[0];
- dev_off=dos3x->dhdr3_off;
- dev_seg=dos3x->dhdr3_seg;
- }
-
- else if ((_os(VERSION,0) & 0xFF) ==2) {
- dos2x=(struct RSV2_X *) &device_fcb.sys_rsv[0];
- dev_off=dos2x->dhdr2_off;
- dev_seg=dos2x->dhdr2_seg;
- }
-
- else { /* Forget it for DOS 1.10 or earlier */
- printf("DOS 2.00 or newer required\n");
- exit(1);
- }
-
- printf(" Device driver chain .... \n\n");
-
- /* Display the current DOS chain of device drivers */
- printf(" ptr type device name strategy ptr interrupt ptr \n");
- printf("---------- ---- ---------------- ------------ ------------- \n");
-
- while((dev_seg != 0xFFFF) & (dev_off != 0xFFFF)) {
- /* device header ptr */
- printf("%04x:%04x ",dev_seg,dev_off);
-
- /* move the device header into the data segment structure "device" */
- _peek(dev_seg,dev_off,&device,sizeof(device));
-
- /* display device attribute word */
- printf(" %04x ",device.attr);
-
-
-
- if ((device.attr & 0x8000) ==0) { /* If block device .... */
- for (j=0;j<=7;j++) /* no device name */
- printf("%02x",device.dname[j]);
- /* strategy end point */
- printf(" %04x:%04x ",dev_seg,device.strat);
- }
-
- else { /* display device name */
- for (j=0;j<=7;j++)
- printf("%c",device.dname[j]);
- /* strategy end point */
- printf(" %04x:%04x ",dev_seg,device.strat);
- }
-
- /* "interupt" entry point */
- printf("%04x:%04x \n",dev_seg,device.intrpt);
-
- dev_seg=device.nxthdr_seg; /* set up ptr to next device header */
- dev_off=device.nxthdr_off; /* and loop back to display it */
- }
- printf("---------- ---- ---------------- ------------ ------------- \n");
- }
-
-
- /* Initialize standard FCB */
- int initfcb(drv,name)
- byte drv;
- char name[];
- {
- int i;
- device_fcb.drive=drv; /* drive designation: default drive=0, A=1 ... */
- for(i=0;i<=10;i++) device_fcb.fname[i]=name[i]; /* device or file name */
- for(i=0;i<=4;i++) device_fcb.bset[i]=0; /* fields not zeroed by open call */
- }
-
- /* Peek memory */
- int _peek(segment,offset,buffer,nbytes)
- unsigned segment; /* segment portion of memory address */
- unsigned offset; /* offset portion of memory address */
- byte *buffer; /* local memory buffer (in data segment) */
- unsigned nbytes; /* number of bytes to transfer */
-
- /*
- macro assembler header:
-
- PGROUP GROUP PROG
- PROG SEGMENT BYTE PUBLIC 'PROG'
- PUBLIC _PEEK
- ASSUME CS:PGROUP
- ;
- _PEEK PROC NEAR
- PUSH BP
- MOV BP,SP */
- {
- #asm
- PUSH DS ;save state
- PUSH SI
- PUSH DI
- PUSH CX
- ;
- MOV DS,WORD [BP+4] ;get source segment
- MOV SI,WORD [BP+6] ;get source offset
- MOV DI,WORD [BP+8] ;get destination offset in ES
- MOV CX,WORD [BP+10] ;get byte count for transfer
- REP MOVSB ;move bytes into local buffer
- ;
- POP CX ;return state
- POP DI
- POP SI
- POP DS
- #
- }
- /* POP BP
- RET
- _PEEK ENDP
- PROG ENDS
- END */
-
-
-